/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.thienloc.omap.controller.scatchcard;

import com.thienloc.omap.entity.TblAlarm;
import com.thienloc.omap.session.TblAlarmFacade;
import com.thienloc.omap.util.JsfUtil;
import java.util.Date;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import org.slf4j.LoggerFactory;

/**
 *
 * @author GiangLT
 */
@ManagedBean
@ViewScoped
public class AlarmBean {

    private Date startDate = new Date();
    private Date endDate = new Date();
    private List<TblAlarm> list;
    @EJB
    private TblAlarmFacade facade;
    private final org.slf4j.Logger logger = LoggerFactory.getLogger(this.getClass());

    @PostConstruct
    public void init() {
        startDate.setHours(0);
        startDate.setHours(0);
        startDate.setHours(0);
        endDate.setHours(23);
        endDate.setHours(59);
        endDate.setHours(59);

        getAlarm();
    }

    public void getAlarm() {
        try {
            list = facade.findByAlarmTimeRange(startDate, endDate);
        } catch (Exception ex) {
            logger.error("", ex);
            JsfUtil.addErrorMessage("Lỗi!", ex.getMessage());
        }
    }

    public List<TblAlarm> getList() {
        return list;
    }

    public Date getStartDate() {
        return startDate;
    }

    public void setStartDate(Date startDate) {
        this.startDate = startDate;
    }

    public Date getEndDate() {
        return endDate;
    }

    public void setEndDate(Date endDate) {
        this.endDate = endDate;
    }
}
